<template>
  <div>
    <div class="post" v-for="(postListData, index) in postList" :key="index">
      <!-- 没有图片 -->
      <div
        class="singleImg"
        v-if="postListData.images.length == 0"
        @click="$router.push('/post/postDetail?id=' + postListData.id)"
      >
        <div class="right-txt">
          <h4 class="post-title">{{ postListData.title }}</h4>
          <p class="post-desc" v-html="postListData.summary">
            {{ postListData.summary }}
          </p>
          <div class="post-info">
            <div class="post-info-left">
              <span>
                <i class="el-icon-location-outline"></i>
                {{ postListData.cityName }}
              </span>
              <div class="post-user">
                by
                <a href="/user/personal"
                  ><img
                    :src="
                      $axios.defaults.baseURL +
                      postListData.account.defaultAvatar
                    "
                    alt=""
                /></a>
                <a href="/user/personal" class="nickname">{{
                  postListData.account.nickname
                }}</a>
              </div>
              <span><i class="el-icon-view"></i>{{ postListData.watch }}</span>
            </div>
            <span class="post-info-right" v-if="postListData.like"
              >{{ postListData.like }} 赞</span
            >
            <span class="post-info-right" v-else>0赞</span>
          </div>
        </div>
      </div>
      <!-- 小于3张 -->
      <div
        class="singleImg"
        v-if="postListData.images.length >= 1 && postListData.images.length < 3"
        @click="$router.push('/post/postDetail?id=' + postListData.id)"
      >
        <div class="leftImg">
          <img :src="postListData.images[0]" alt class="cover" />
        </div>
        <div class="right-txt">
          <h4 class="post-title">{{ postListData.title }}</h4>
          <p class="post-desc" v-html="postListData.summary">
            {{ postListData.summary }}
          </p>
          <div class="post-info">
            <div class="post-info-left">
              <span>
                <i class="el-icon-location-outline"></i>
                {{ postListData.cityName }}
              </span>
              <div class="post-user">
                by
                <a href="/user/personal"
                  ><img
                    :src="
                      $axios.defaults.baseURL +
                      postListData.account.defaultAvatar
                    "
                    alt=""
                /></a>
                <a href="/user/personal" class="nickname">{{
                  postListData.account.nickname
                }}</a>
              </div>
              <span><i class="el-icon-view"></i>{{ postListData.watch }}</span>
            </div>
            <span class="post-info-right" v-if="postListData.like"
              >{{ postListData.like }} 赞</span
            >
            <span class="post-info-right" v-else>0赞</span>
          </div>
        </div>
      </div>
      <!-- 大于3张 -->
      <div
        class="multipImgs"
        v-else-if="postListData.images.length >= 3"
        @click="$router.push('/post/postDetail?id=' + postListData.id)"
      >
        <div class="title">{{ postListData.title }}</div>
        <div class="content">{{ postListData.summary }}</div>
        <div class="picture">
          <img :src="postListData.images[0]" alt class="cover" />
          <img :src="postListData.images[1]" alt class="cover" />
          <img :src="postListData.images[2]" alt class="cover" />
        </div>
        <div class="postInfo">
          <div class="left">
            <span class="el-icon-location-outline">{{
              postListData.cityName
            }}</span>
            <div class="post-user">
              by
              <a href="/user/personal"
                ><img
                  :src="
                    $axios.defaults.baseURL + postListData.account.defaultAvatar
                  "
                  alt=""
              /></a>
              <a href="/user/personal" class="nickname">{{
                postListData.account.nickname
              }}</a>
            </div>
            <span class="el-icon-view">{{ postListData.watch }}</span>
          </div>
          <div class="right">
            <span v-if="postListData.like">{{ postListData.like }}赞</span>
            <span v-else>0赞</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    postList: Array,
    default: [],
  },
  data() {
    return {};
  },
};
</script>

<style lang="less" scoped>
.post {
  width: 100%;
  display: flex;
}
.singleImg {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid #eee;
  .leftImg {
    cursor: pointer;
    width: 220px;
    height: 150px;
    overflow: hidden;
    flex-shrink: 0;
    margin-right: 10px;

    img {
      width: 100%;
      height: 100%;
    }
  }
  .right-txt {
    width: 100%;
    flex: 1;
    cursor: pointer;
    .post-title:hover {
      color: orange;
    }
    .post-title {
      cursor: pointer;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-bottom: 15px;
      font-weight: 400;
      font-size: 18px;
    }
    .post-desc {
      margin-bottom: 15px;
      line-height: 1.5;
      font-size: 14px;
      height: 63px;
      color: #666;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
    }
    .post-info {
      display: flex;
      justify-content: space-between;

      .post-info-left {
        display: flex;
        align-items: center;

        font-size: 12px;
        color: #999;
        margin-right: 10px;
        span {
          margin-right: 10px;
        }
        .post-user img {
          display: block;
          width: 16px;
          height: 16px;
          border-radius: 100px;
          margin: 5px;
        }
        .post-user {
          display: flex;
          align-items: center;
          margin-right: 10px;
          a {
            color: orange;
          }
        }
      }

      .post-info-right {
        color: orange;
        font-size: 16px;
      }
    }
  }
}

.multipImgs {
  width: 100%;
  padding-top: 20px;

  .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 15px;
    font-weight: 400;
    font-size: 18px;
    cursor: pointer;
  }
  .title:hover {
    color: #ffa500;
  }

  .content {
    margin-bottom: 15px;
    line-height: 1.5;
    font-size: 14px;
    height: 63px;
    overflow: hidden;

    text-overflow: ellipsis;
  }
  .picture {
    display: flex;
    justify-content: space-between;
    margin: 15px 0;
    .cover {
      width: 220px;
      height: 150px;
      object-fit: cover;
      cursor: pointer;
    }
  }
  .postInfo {
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;

    justify-content: space-between;
    display: flex;
    .left {
      color: #666666;
      font-size: 12px;
      display: flex;
      align-items: center;
      margin-right: 10px;

      .post-user {
        display: flex;
        align-items: center;
        margin-right: 10px;
        a {
          color: #ffa500;
        }
        img {
          display: block;
          width: 16px;
          height: 16px;
          border-radius: 100px;
          margin: 5px;
        }
      }
    }
    .right {
      font-size: 16px;
      color: #ffa500;
    }
  }
}
.singleImg {
  width: 100%;
  padding-top: 20px;

  display: flex;
  .leftImg {
    width: 220px;
    height: 150px;
    overflow: hidden;
    flex-shrink: 0;
    margin-right: 10px;
    .cover {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .rightContent {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    .title {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-bottom: 15px;
      font-weight: 400;
      font-size: 18px;
    }
    .title:hover {
      color: #ffa500;
    }
    .content {
      margin-bottom: 15px;
      line-height: 1.5;
      font-size: 14px;
      height: 63px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
    }
    .postInfo {
      width: 100%;
      display: flex;

      justify-content: space-between;
      padding-bottom: 20px;
      border-bottom: 1px solid #eee;
      .left {
        color: #666666;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        .userInfo {
          display: flex;
          justify-content: center;
          align-items: center;
          margin: 0 10px;
          .userName {
            color: #ffa500;
          }
          img {
            display: block;
            width: 16px;
            height: 16px;
            border-radius: 100px;
            margin: 5px;
          }
        }
      }
      .right {
        flex: 1;
        font-size: 16px;
        color: #ffa500;
        text-align: right;
      }
    }
  }
}
</style>
